import json

import execjs
import requests

headers = {
    'Accept': '*/*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Origin': 'https://www.aqistudy.cn',
    'Pragma': 'no-cache',
    'Referer': 'https://www.aqistudy.cn/html/city_realtime.php?v=2.3',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0',
    'X-Requested-With': 'XMLHttpRequest',
    'sec-ch-ua': '"Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

data = {
    'city': '成都'
}

prams = execjs.compile(open('main.js', 'r', encoding='utf-8').read()).call('encodeData', data)

data = {
    'hXhY1B2Kd': prams
}

response = requests.post('https://www.aqistudy.cn/apinew/aqistudyapi.php', headers=headers, data=data, verify=false)

print(response.text)

result = execjs.compile(open('main.js', 'r', encoding='utf-8').read()).call('decodeData', response.text)
for it in json.loads(result)['result']['data']['rows']:
    print(it)
